package aes.acctest;

import aes.server.QuestionsManager;
import common.Question;

import fit.ActionFixture;


public class AddQuestion extends ActionFixture {
	
	private Question q = new Question();
	
	//check all setters
	//id
	public int questionId() {
		return q.getId();
	}
	
	public int setNegativeQuestionId() {
		q.setId(-1);
		return q.getId();
	}
	public int setSmallQuestionId() {
		q.setId(22);
		return q.getId();
	}
	public int setLargeQuestionId() {
		q.setId(999999);
		return q.getId();
	}
	public int setCorrectQuestionId() {
		q.setId(55555);
		return q.getId();
	}
	
	//question
	public boolean question(){ //check is question is null
		return (q.getQuestion()==null);
	}
	
	public boolean WrongQuestion(){ //checks question length condition
				q.setQuestion("");
				return (q.getQuestion()==null);
	}
	public String WriteQuestion(){
		q.setQuestion("2+2=?");
		return q.getQuestion();
    }
	//answers
	public boolean answers(){
		return (q.getAnswers()==null);
	}
	public boolean WrongAnswers1(){
		String[] an={};

		q.setAnswers(an);
		return (q.getAnswers()==null);
		
	}
	public boolean WrongAnswers2(){
		String[] an={"","1","2","4"}; //checks set answer conditions
		q.setAnswers(an);
		return (q.getAnswers()==null);
		
	}
	public boolean WrongAnswers3(){
		String[] an={"1","","2","4"};
		q.setAnswers(an);
		return (q.getAnswers()==null);
		
	}
	public boolean WrongAnswers4(){
		String[] an={"1","2","","4"};
		q.setAnswers(an);
		return (q.getAnswers()==null);
		
	}
	public boolean WrongAnswers5(){
		String[] an={"1","2","4",""};
		q.setAnswers(an);
		return (q.getAnswers()==null);
		
	}
	
	public String WriteAnswers(){
		String[] an={"0","1","2","4"};
		q.setAnswers(an);
		return (String)(q.getAnswers()[0].toString()+" "+q.getAnswers()[1].toString()+" "+q.getAnswers()[2].toString()+" "+q.getAnswers()[3].toString());
	}
	
	//correct answer
	public int correctAnswer() {
		return q.getCorrectAnswer();
	}
	
	public int SmallCorrectAnswer(){
		q.setCorrectAnswer(-1);
		return q.getCorrectAnswer();
	}
	
	public int LargeCorrectAnswer(){
		q.setCorrectAnswer(6);
		return q.getCorrectAnswer();
	}
	
	public int WriteCorrectAnswer1(){
		q.setCorrectAnswer(1);
		return q.getCorrectAnswer();
	}
	public int WriteCorrectAnswer2(){
		q.setCorrectAnswer(2);
		return q.getCorrectAnswer();
	}
	public int WriteCorrectAnswer3(){
		q.setCorrectAnswer(3);
		return q.getCorrectAnswer();
	}
	public int WriteCorrectAnswer4(){
		q.setCorrectAnswer(4);
		return q.getCorrectAnswer();
	}
	
	//teacherId
	public int teacherID() {
		return q.getTeacherId();
	}
	
	public int WrongTeacherID() {
		q.setTeacherId(-1);
		return q.getTeacherId();
	}
	public int WriteTeacherID() {
		q.setTeacherId(22);
		return q.getTeacherId();
	}
	//subjectID
	public int getNotExistentsubjectID() {
		Question q1=new Question();
		return q1.getSubject();
	}
	
	public int getExistsSubjectID() {
		return q.getSubject();
	}
	//points
	public int points() {
		return q.getPoints();
	}
	public int LargePoints() {
		q.setPoints(200);
		return q.getPoints();
	}
	public int SmallPoints() {
		q.setPoints(-2);
		return q.getPoints();
	}
	public int CorrectPoints() {
		q.setPoints(100);
		return q.getPoints();
	}
	
	//get question by id (existent question(qestion.id==id that required question !=null) and not existent(null))
	public boolean getExistentQuestionById(){
		q=QuestionsManager.getQuestion(2001);
		if(q.getId()==2001 && q!=null)
			return true;
		return false;
	}
	public boolean getNotExistentQuestionById(){
		q=QuestionsManager.getQuestion(20);
		if(q==null)
			return true;
		return false;
	}
	//save question (create and add ) + get question(all fields are correct)
	public boolean saveQuestion(){
		//create question
		Question q2= new Question();
		q2.setId(4444);
		q2.setQuestion("7%2=?");
		String[] an={"0","1","20","5"};
		q2.setAnswers(an);
		q2.setCorrectAnswer(2);
		q2.setTeacherId(2);
		//add question to DB
		QuestionsManager.addQuestion(q2);
		//get question from DB
		Question q1= new Question();
		q1=QuestionsManager.getQuestion(q2.getId());
		if((q1.getId()==q2.getId())&&(q1.getCorrectAnswer()==q2.getCorrectAnswer())&&(q1.getTeacherId()==q2.getTeacherId())
				&& (q1.getAnswers()[0].equals(q2.getAnswers()[0])) && (q1.getAnswers()[1].equals(q2.getAnswers()[1]))
				&& (q1.getAnswers()[2].equals(q2.getAnswers()[2])) && (q1.getAnswers()[3].equals(q2.getAnswers()[3]))
				&& (q1.getQuestion().equals(q2.getQuestion())))
			return true;
		return false;
	}
	
    //all fields are filled
	
	public boolean AddQuestion1(){
		//All parameters are correct
		Question q2= new Question();
		//forgot question id
		q2.setQuestion("9%2=?");
		String[] an={"0","1","20","5"};
		q2.setAnswers(an);
		q2.setCorrectAnswer(2);
		q2.setTeacherId(2);
		//save
		return QuestionsManager.addQuestion(q2);
			
	}
	public boolean AddQuestion2(){
		//All parameters are correct
		Question q2= new Question();
		q2.setId(5555);
		//forgot question
		String[] an={"0","1","20","5"};
		q2.setAnswers(an);
		q2.setCorrectAnswer(2);
		q2.setTeacherId(2);
		//save
		return QuestionsManager.addQuestion(q2);
			
	}
	public boolean AddQuestion3(){
		//All parameters are correct
		Question q2= new Question();
		q2.setId(5555);
		q2.setQuestion("9%2=?");
		//forgot answers
		q2.setCorrectAnswer(2);
		q2.setTeacherId(2);
		//save
		return QuestionsManager.addQuestion(q2);
			
	}
	public boolean AddQuestion4(){
		//All parameters are correct
		Question q2= new Question();
		q2.setId(5555);
		q2.setQuestion("9%2=?");
		//forgot answer
		String[] an={"1","20","5"};
		q2.setAnswers(an);
		q2.setCorrectAnswer(2);
		q2.setTeacherId(2);
		//save
		return QuestionsManager.addQuestion(q2);
			
	}
	public boolean AddQuestion5(){
		//All parameters are correct
		Question q2= new Question();
		q2.setId(5555);
		q2.setQuestion("9%2=?");
		//empty answer
		String[] an={"","1","20","5"};
		q2.setAnswers(an);
		q2.setCorrectAnswer(2);
		q2.setTeacherId(2);
		//save
		return QuestionsManager.addQuestion(q2);
	}
		public boolean AddQuestion6(){
			//All parameters are correct
			Question q2= new Question();
			q2.setId(5555);
			q2.setQuestion("9%2=?");
			String[] an={"","1","20","5"};
			q2.setAnswers(an);
			//forgot correct answer
			q2.setTeacherId(2);
			//save
			return QuestionsManager.addQuestion(q2);
					
	}
		public boolean AddQuestion7(){
			//All parameters are correct
			Question q2= new Question();
			q2.setId(5555);
			q2.setQuestion("9%2=?");
			String[] an={"","1","20","5"};
			q2.setAnswers(an);
			q2.setCorrectAnswer(2);
			//forgot teacher id
			//save
			return QuestionsManager.addQuestion(q2);
					
	}
		public boolean addExistentQuestion(){
			Question q2= new Question();
			q2.setId(4012);
			q2.setQuestion("7%2=?");
			String[] an={"0","1","20","5"};
			q2.setAnswers(an);
			q2.setCorrectAnswer(2);
			q2.setTeacherId(2);
			
			return QuestionsManager.addQuestion(q2);
		}
			
		}
